﻿using System.Linq;
using System.Web.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;
using Omu.AwesomeDemo.Infra.Dto;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class AutocompleteDemoController : BaseController
    {
        private readonly IRepo<Person> repo;

        public AutocompleteDemoController(IRepo<Person> repo)
        {
            this.repo = repo;
        }

        public ActionResult Index()
        {
            var man = repo.GetAll().FirstOrDefault() ?? new Person { Id = 1, FirstName = "foo", LastName = "bar" };
            var input = new AutocompleteDemoInput
                            {
                                Character2 = man.FirstName + " " + man.LastName,
                                Character2Id = man.Id
                            };
            return View(input);
        }

        [HttpPost]
        public ActionResult Index(AutocompleteDemoInput input)
        {
            return View(input);
        }
    }
}